{extend name="public/container"}
{block name="head_top"}
<style type="text/css">
.health {
    color: green;
}
.unhealth {
    color: #E6A23C;
}
.health div{
    background-color: green;
    width: 6px;
    height: 14px;
    margin-right: 2px;
}
.unhealth div{
    background-color: #E6A23C;
    width: 6px;
    height: 14px;
    margin-right: 2px;
}
.text-one{
    text-overflow: ellipsis;
    overflow: hidden;
    white-space: nowrap;
}
</style>
{/block}

{block name="content"}
<div id="myApp" v-cloak>
    <div class="douxue-filter padding-20 flex flex-between" style="margin-bottom:20px">
        <el-form :inline="true" :model="where" size="mini" label-width="0px" class="flex">
            <div class="flex flex-between">
                <el-form-item label="">
                    <el-input size="small" v-model="where.tour_perfer" placeholder="出游喜好"></el-input>
                </el-form-item>

                <el-form-item label="">
                    <el-input size="small" v-model="where.tour_target" placeholder="意向景点"></el-input>
                </el-form-item>

                <el-form-item label="">
                    <el-select v-model="where.status" size="small" clearable placeholder="状态">
                        <el-option label="正常" value="1"></el-option>
                        <el-option label="禁用" value="0"></el-option>
                    </el-select>
                </el-form-item>

                <el-form-item label="" v-if="is_senior_admin">
                    <el-select v-model="where.sales_admin_id" size="small" clearable placeholder="所属销售" clearable>
                        <el-option
                          v-for="item in salesList"
                          :key="item.admin_id"
                          :label="item.full_name"
                          :value="item.admin_id">
                        </el-option>
                    </el-select>
                </el-form-item>

                <el-form-item label="" v-if="is_senior_admin">
                    <el-select v-model="where.processon_ignore_days" size="small" clearable placeholder="跟进状态" clearable>
                        <el-option
                          v-for="(item,key) in processonStatus"
                          :key="key"
                          :label="item.text"
                          :value="item.day">
                        </el-option>
                    </el-select>
                </el-form-item>

                <el-form-item label="">
                    <el-input size="small" v-model="where.keyword" placeholder="手机号/姓名">
                        <el-button slot="append" size="small" type="danger" @click="doLoadRows(1)">搜索</el-button>
                    </el-input>
                </el-form-item>
            </div>
        </el-form>
    </div>

    <div class="padding-10">
        <div class="flex" style="justify-content: space-between; padding: 10px 0;">
            <div class="left-opt-btns">
                <template v-if="multipleSelectionUids.length > 0">
                    <el-button size="mini" style="margin: 0;" type="warning" @click="doBind(multipleSelectionUids)" v-if="is_senior_admin">绑定</el-button>
                </template>
            </div>

            <div class="right-opt-btns">
                <el-upload
                    action="/admin/user.user/uploadTemplete"
                    :on-success="handleTemplateSuccess"
                    :before-upload="onChangeTemplate"
                    :show-file-list="false"
                    accept="application/vnd.ms-excel,.xls,.xlsx"
                    :limit="1">
                    <el-link :underline="false" type="success" icon="el-icon-upload" style="margin-left:16px">导入用户</el-link>
                </el-upload>
            </div>
        </div>
        <el-table
            :data="rows"
            style="width: 100%"
            v-loading="loading"
            border
            element-loading-text="加载中"
            element-loading-spinner="el-icon-loading"
            @selection-change="handleSelectionChange"
            size="mini">
            <el-table-column
                type="selection"
                width="55">
            </el-table-column>

            <el-table-column
                prop="uid"
                label="ID"
                width="60"
                align="left">
            </el-table-column>

            <el-table-column
                prop="nickname"
                label="客户昵称"
                width="120"
                align="left">
                <template slot-scope="scope">
                    <el-link :underline="false" type="primary">
                        <div class="text-one" style="width: 100px">{{ scope.row.nickname }}</div>
                    </el-link>
                </template>
            </el-table-column>

            <el-table-column
                prop="idcard"
                label="客户实名"
                width="200"
                align="left">
                <template slot-scope="scope">
                    <div v-if="scope.row.is_idcheck>0&&scope.row.idcard">
                        <div class="flex">
                            <div style="width: 30px">姓名:</div>
                            <div style="flex:1; word-break: break-all;">{{ scope.row.idcard.realname }}</div>
                        </div>
                        <div class="flex">
                            <div style="width: 30px">号码:</div>
                            <div style="flex:1; word-break: break-all;">{{ scope.row.idcard.idnumber }}</div>
                        </div>
                        <div class="flex">
                            <div style="width: 30px">地址:</div>
                            <div style="flex:1; word-break: break-all;">{{ scope.row.idcard.address }}</div>
                        </div>
                    </div>
                    <el-link :underline="false" type="danger" v-else>未实名</el-link>
                </template>
            </el-table-column>

            <!-- <el-table-column
                prop="nickname"
                label="客户头像"
                width="140"
                align="left">
                <template slot-scope="scope">
                    <el-avatar :size="50" :src="scope.row.avatar"></el-avatar>
                </template>
            </el-table-column> -->

            <el-table-column
                prop="mobile"
                label="手机号"
                width="140"
                align="left">
            </el-table-column>

            <el-table-column
                prop="mate_mobile"
                label="亲属手机号"
                width="140"
                align="left">
            </el-table-column>

            <el-table-column
                prop="golds"
                label="金币余额"
                width="120"
                align="left">
                <template slot-scope="scope">
                    <el-link :underline="false" type="primary">{{ scope.row.golds }}</el-link>
                </template>
            </el-table-column>

            <el-table-column
                prop="sales_admin_id"
                label="所属销售"
                width="120"
                align="left">
                <template slot-scope="scope">
                    <el-link :underline="false" type="success" v-if="scope.row.sales_admin_id">{{ scope.row.sales_name }}</el-link>
                    <el-link :underline="false" type="danger" v-else>未绑定</el-link>
                </template>
            </el-table-column>

            <el-table-column
                prop="last_time"
                label="最后登录时间"
                width="140"
                align="left">
            </el-table-column>

             <el-table-column
                prop="register_date"
                label="注册时间"
                width="150"
                align="left">
            </el-table-column>

            <el-table-column
                prop="cus_from"
                label="客户来源"
                width="120"
                align="left">
            </el-table-column>

            <el-table-column
                prop="wheregone"
                label="去过景点"
                width="140"
                align="left">
            </el-table-column>

            <el-table-column
                prop="tour_target"
                label="意向景点"
                width="140"
                align="left">
            </el-table-column>

            <el-table-column
                prop="remark"
                label="备注"
                width="140"
                align="left">
            </el-table-column>

            <el-table-column
                prop="address"
                label="客户地址"
                width="200"
                align="left">
                <template slot-scope="scope">
                    <div v-if="scope.row.address">
                        <div class="flex" v-for="add in scope.row.address">
                            <div style="font-size: 13px">{{ add.province }}{{ add.city }}{{ add.area }} {{ add.details }}</div>
                        </div>
                    </div>
                    <el-link :underline="false" type="danger" v-else>无地址</el-link>
                </template>
            </el-table-column>

            <el-table-column
                prop="birthday"
                width="140"
                label="客户生日"
                align="left">
                <template slot-scope="scope">
                    <div>
                        <div class="flex">
                            {{ scope.row.birthday == '0000-00-00' ? '未设置' : scope.row.birthday }}
                        </div>

                        <!-- 跟进健康状态检查 -->
                        <div style="align-items: center;" v-if="scope.row.birthday != '0000-00-00'">
                            <div class="flex">
                                <div style="margin-right: 10px;">销售</div>
                                <div :class="[scope.row.birthdayb==1?'health':'unhealth']" style="font-size: 12px">{{ scope.row.birthdayb_text }}</div>
                            </div>
                            <div class="flex">
                                <div style="margin-right: 10px;">客户</div>
                                <div :class="[scope.row.birthdayc==1?'health':'unhealth']" style="font-size: 12px">{{ scope.row.birthdayc_text }}</div>
                            </div>
                        </div>
                    </div>
                </template>
            </el-table-column>

            <el-table-column
                prop="mobile"
                width="200"
                label="跟进情况"
                align="left">
                <template slot-scope="scope">
                    <div>
                        <div class="flex">
                            <div style="margin-right: 10px;">最近：</div>
                            <div v-if="scope.row.last_processon_time">
                                <el-tooltip class="item" effect="light" placement="left">
                                    <div>
                                        <i class="el-icon-question"></i> 
                                        <span>{{ scope.row.last_processon_time }}</span>
                                    </div>
                                    <div slot="content">
                                        <div class="processlist" style="width: 400px ; max-height: 300px; overflow-y: scroll; padding: 14px 20px;">
                                            <div class="processitem">
                                                <div class="flex">
                                                    <div style="width: 130px">跟进时间</div>
                                                    <div style="flex: 1">跟进内容</div>
                                                </div>
                                                <div style="margin: 8px 0; font-size: 12px; color: #666" class="flex" v-for="item in scope.row.processon_records">
                                                    <div style="width: 130px;">{{ item.ontime }}</div>
                                                    <div style="flex: 1">{{ item.content }}</div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </el-tooltip>
                            </div>
                            <div style="color: red" v-else>从未跟进</div>
                        </div>

                        <!-- 跟进健康状态检查 -->
                        <div class="flex" style="align-items: center;" v-if="scope.row.last_processon_time">
                            <div style="margin-right: 10px;">
                                <div :class="[scope.row.processon_ignore_days > 15?'unhealth':'health','flex']">
                                    <div></div>
                                    <div></div>
                                    <div></div>
                                </div>
                            </div>
                            <div :class="[scope.row.processon_ignore_days > 15?'unhealth':'health']">{{ scope.row.processon_ignore_text }}</div>
                        </div>
                    </div>
                </template>
            </el-table-column>

            <el-table-column
                prop="mobile"
                width="200"
                label="收回总账"
                align="left">
                <template slot-scope="scope">
                    <div>
                        <el-tag v-if="scope.row.unfollow_record_time=='NONE'" size="mini" type="info">未超30天</el-tag>
                        <template v-else>
                            <template v-if="scope.row.unfollow_handle_status==0">
                                <el-button size="mini" type="success" @click="confirmGetBack(scope.row.unfollow_record_id , 1)">确认</el-button>
                                <el-button size="mini" type="danger" @click="confirmGetBack(scope.row.unfollow_record_id , 2)">取消</el-button>
                            </template>
                            <template v-else>
                                <el-tag size="mini" type="info">{{ scope.row.unfollow_handle_status==1?'已确认收回':'已确认取消'}}</el-tag>
                            </template>
                        </template>
                    </div>
                </template>
            </el-table-column>

            <el-table-column
                prop="status_display"
                label="状态"
                width="120"
                align="left">
                <template slot-scope="scope">
                    <el-button type="danger" size="mini" v-if="scope.row.status == 2">{{ scope.row.status_display }}</el-button>
                    <el-switch
                        v-model="scope.row.status"
                        v-else
                        active-color="#ff6a6c"
                        inactive-color="#999"
                        :active-value="1"
                        :inactive-value="0"
                        @change="doSetStatus(scope.row)">
                    </el-switch>
                </template>
            </el-table-column>

            <el-table-column
                label="操作"
                fixed="right"
                width="80"
                align="center">
                <template slot-scope="scope">
                    <el-button size="mini" style="margin: 0;" type="success" @click="doModify(scope.row)">标注</el-button>
                    <el-button size="mini" style="margin: 0;" type="warning" @click="doBind(scope.row.uid)" v-if="is_senior_admin">绑定</el-button>
                    <el-button size="mini" style="margin: 0;" type="danger" @click="doDelete(scope.row.uid)" v-if="is_senior_admin">删除</el-button>
                    <el-button size="mini" style="margin: 0;" type="primary" @click="doIssueCoupon(scope.row.uid)">发券</el-button>
                    <el-button size="mini" style="margin: 0;" type="danger" @click="doIssueGolds(scope.row.uid)">金币</el-button>
                </template>
            </el-table-column>
        </el-table>
        <div class="pagination">
            <el-pagination
                hide-on-single-page
                small
                layout="prev, pager, next"
                :total="rowsCount"
                :page-size="where.limit"
                @current-change="doLoadRows">
            </el-pagination>
        </div>
    </div>

    <!-- 修改  -->
    <el-dialog title="编辑" :visible.sync="dialogFormVisible" @close='closeDialog'>
        <el-form :model="formData" :rules="rules" ref="formData" size="mini" label-width="100px" >
            <el-form-item label="真实姓名" prop="full_name">
                <el-input v-model="formData.full_name"></el-input>
            </el-form-item>

            <el-form-item label="身份证号" prop="idcard">
                <el-input type="text" v-model="formData.idcard.idnumber"></el-input>
            </el-form-item>

            <el-form-item label="客户地址" prop="address">
                <div class="flex">
                    <div style="width:80px;margin-right: 6px;">
                        <el-input v-model="formData.address.province" placeholder="省/州"></el-input>
                    </div>
                    <div style="width:80px;margin-right: 6px;">
                        <el-input v-model="formData.address.city" placeholder="市"></el-input>
                    </div>
                    <div style="width:80px;margin-right: 6px;">
                        <el-input v-model="formData.address.area" placeholder="县/市"></el-input>
                    </div>
                    <div style="flex: 1;">
                        <el-input v-model="formData.address.address" placeholder="详细地址"></el-input>
                    </div>
                </div>
            </el-form-item>

            <el-form-item label="手机号码" prop="mobile">
                <el-input v-model="formData.mobile"></el-input>
            </el-form-item>

            <el-form-item label="客户生日" prop="birthday">
                <el-date-picker
                    v-model="formData.birthday"
                    type="date"
                    value-format="yyyy-MM-dd"
                    placeholder="选择日期">
                </el-date-picker>
            </el-form-item>

            <el-form-item label="客户来源" prop="cus_from">
                <el-input v-model="formData.cus_from"></el-input>
            </el-form-item>

            <el-form-item label="出游喜好" prop="tour_perfer">
                <el-input type="textarea" row="4" maxlength="80" show-word-limit v-model="formData.tour_perfer"></el-input>
            </el-form-item>

            <el-form-item label="意向景点" prop="tour_target">
                <el-input type="textarea" row="4" maxlength="80" show-word-limit v-model="formData.tour_target"></el-input>
            </el-form-item>

            <el-form-item label="去过景点" prop="wheregonge">
                <el-input type="textarea" row="4" maxlength="80" show-word-limit v-model="formData.wheregone"></el-input>
            </el-form-item>

            <el-form-item label="备注信息" prop="remark">
                <el-input type="textarea" row="4" maxlength="80" show-word-limit v-model="formData.remark"></el-input>
            </el-form-item>

            <el-form-item label="性别" prop="gender">
                <el-radio v-model="formData.gender" :label="1">男</el-radio>
                <el-radio v-model="formData.gender" :label="2">女</el-radio>
            </el-form-item>

            <el-form-item label="状态" prop="gender">
                <el-radio v-model="formData.status" :label="0" :checked="true" >禁用</el-radio>
                <el-radio v-model="formData.status" :label="1">激活</el-radio>
            </el-form-item>

            <el-form-item>
                <el-button type="primary" @click="doSave('formData')">确 定</el-button>
                <el-button @click="dialogFormVisible = false">取消</el-button>
            </el-form-item>
        </el-form>
    </el-dialog>

    <!-- 绑定销售经理  -->
    <el-dialog title="绑定销售经理" :visible.sync="dialogBindVisible">
        <el-form :model="bindForm" ref="formData" label-width="100px">
            <el-form-item label="销售经理" prop="sales_id">
                <el-select
                    v-model="bindForm.sales_id"
                    placeholder="销售经理">
                    <el-option
                      v-for="item in salesList"
                      :key="item.id"
                      :label="item.full_name"
                      :value="item.id">
                    </el-option>
                </el-select>
            </el-form-item>

            <el-form-item>
                <el-button size="small" type="primary" @click="doSaveBind()">确 定</el-button>
                <el-button size="small" @click="dialogBindVisible = false">取消</el-button>
            </el-form-item>
        </el-form>
    </el-dialog>

    <!-- 发放代金券  -->
    <el-dialog title="发放代金券" :visible.sync="sendCouponFlag" width="70%">
        <div>
            <el-form :model="couponForm" ref="formData" label-width="100px">
                <el-form-item label="选择代金券" prop="sales_id">
                    <el-select
                        v-model="couponForm.coupon_id"
                        filterable
                        placeholder="选择代金券">
                        <el-option
                          v-for="item in coupons"
                          :key="item.id"
                          :label="item.title"
                          :value="item.id">
                        </el-option>
                    </el-select>
                </el-form-item>

                <el-form-item>
                    <el-button size="small" type="primary" @click="doSaveIssue()">确定赠送</el-button>
                    <el-button size="small" @click="sendCouponFlag = false">取消</el-button>
                </el-form-item>
            </el-form>
        </div>

        <div>
            <div style="font-size: 16px; font-weight: bold; margin-bottom: 20px; color: #333">代金券记录</div>
            <el-table
                :data="couponRecords.rows"
                style="width: 100%"
                v-loading="couponRecordsLoading"
                element-loading-text="加载中"
                element-loading-spinner="el-icon-loading"
                size="mini">
                <el-table-column
                    prop="title"
                    label="领取用户"
                    align="left">
                    <template slot-scope="scope">
                        <div>
                            <el-link :underline="false" type="primary">{{ scope.row.nickname }}（UID：{{ scope.row.uid }}）</el-link>
                        </div>
                        <div>
                            <el-link :underline="false" type="primary">{{ scope.row.mobile }}</el-link>
                        </div>
                    </template>
                </el-table-column>

                <el-table-column
                    prop="obtain_type_display"
                    label="获取方式"
                    width="100"
                    align="left">
                </el-table-column>

                <el-table-column
                    prop="obtain_time"
                    label="领取时间"
                    width="160"
                    align="left">
                </el-table-column>

                <el-table-column
                    prop="expire_time"
                    label="过期时间"
                    width="160"
                    align="left">
                </el-table-column>

                <el-table-column
                    prop="status_display"
                    label="领取状态"
                    width="120"
                    align="left">
                    <template slot-scope="scope">
                        <el-tag size="mini" type="success" v-if="scope.row.status==1">{{ scope.row.status_display }}</el-tag>
                        <el-tag size="mini" type="info" v-if="scope.row.status==2">{{ scope.row.status_display }}</el-tag>
                        <el-tag size="mini" type="danger" v-if="scope.row.status==3">{{ scope.row.status_display }}</el-tag>
                        <el-tag size="mini" type="warning" v-if="scope.row.status==4">{{ scope.row.status_display }}</el-tag>
                    </template>
                </el-table-column>

                <el-table-column
                    prop="use_time_display"
                    label="使用状态"
                    width="160"
                    align="left">
                    <template slot-scope="scope">
                        <div>
                            <el-link :underline="false" type="primary">时间：{{ scope.row.use_time_display }}</el-link>
                        </div>
                        <div>
                            <el-link :underline="false" type="danger">核销：{{ scope.row.use_type_display }}</el-link>
                        </div>
                    </template>
                </el-table-column>

                <el-table-column
                    prop="use_time_display"
                    label="操作"
                    width="80"
                    fixed="right"
                    align="right">
                    <template slot-scope="scope">
                        <div>
                            <el-link :underline="false" type="warning" v-if="scope.row.use_type==0" @click="verifyCoupon(scope.row.id)">核销</el-link>
                        </div>
                    </template>
                </el-table-column>
            </el-table>
            <div class="pagination">
                <el-pagination
                    small
                    :hide-on-single-page="true"
                    layout="prev, pager, next"
                    :total="couponRecords.rowsCount"
                    :page-size="couponRecordsWhere.limit"
                    @current-change="doLoadCouponRecordsRows">
                </el-pagination>
            </div>
        </div>
    </el-dialog>

    <!-- 发放金币  -->
    <el-dialog title="发放金币" :visible.sync="sendGoldsFlag" width="70%">
        <div>
            <el-form :model="goldsForm" ref="formData" label-width="100px">
                <el-form-item label="金币数量" prop="golds">
                    <el-input type="number" v-model="goldsForm.golds" placeholder="金币数量" />
                </el-form-item>

                <el-form-item label="原因备注" prop="remark">
                    <el-input type="textarea" v-model="goldsForm.remark" rows="4" placeholder="原因备注,选填" />
                </el-form-item>

                <el-form-item>
                    <el-button size="small" type="primary" @click="doSaveIssueGolds()">确定赠送</el-button>
                    <el-button size="small" @click="sendGoldsFlag = false">取消</el-button>
                </el-form-item>
            </el-form>
        </div>

        <div>
            <div style="font-size: 16px; font-weight: bold; margin-bottom: 20px; color: #333">金币记录</div>
            <el-table
                :data="goldsRecords.rows"
                style="width: 100%"
                v-loading="goldsRecordsLoading"
                element-loading-text="加载中"
                element-loading-spinner="el-icon-loading"
                size="mini">
                <el-table-column
                    prop="create_time"
                    label="发生时间"
                    width="160"
                    align="left">
                </el-table-column>

                <el-table-column
                    prop="amt"
                    label="发生数量"
                    width="160"
                    align="center">
                    <template slot-scope="scope">
                        <el-link size="mini" :underline="false" type="danger" v-if="scope.row.amt >= 0">+{{ scope.row.amt }}</el-link>
                        <el-link size="mini" :underline="false" type="success" v-if="scope.row.amt < 0">{{ scope.row.amt }}</el-link>
                    </template>
                </el-table-column>

                <el-table-column
                    prop="balance"
                    label="当期余额"
                    width="160"
                    align="center">
                </el-table-column>

                <el-table-column
                    prop="stype_display"
                    label="发生类型"
                    width="160"
                    align="left">
                </el-table-column>

                <el-table-column
                    prop="remark"
                    label="备注"
                    width="160"
                    align="left">
                </el-table-column>
            </el-table>
            <div class="pagination">
                <el-pagination
                    small
                    :hide-on-single-page="true"
                    layout="prev, pager, next"
                    :total="goldsRecords.rowsCount"
                    :page-size="goldsRecordsWhere.limit"
                    @current-change="doLoadGoldsRecordsRows">
                </el-pagination>
            </div>
        </div>
    </el-dialog>

    <!-- 用户导入  -->
    <el-dialog title="导入确认" :visible.sync="waitingUploadUserFlag" width="70%">
        <div>
            <el-alert v-if="checkFalse" title="检测到本次待上传数据中存在重复数据，请仔细检查后删除重复数据再提交" type="error"></el-alert>
            <el-table
                :data="waitingUploadUser"
                style="width: 100%"
                height="300"
                size="mini">
                <el-table-column
                    prop="remark"
                    label="检测结果"
                    width="80"
                    fixed="left"
                    align="center">
                    <template slot-scope="scope">
                        <el-tag type="success" size="mini" v-if="scope.row.repeat_flag==0">检测正常</el-tag>
                        <el-tag type="warning" size="mini" v-if="scope.row.repeat_flag==1">表格重复</el-tag>
                        <el-tag type="danger" size="mini" v-if="scope.row.repeat_flag==2">系统重复</el-tag>
                    </template>
                </el-table-column>

                <el-table-column
                    prop="full_name"
                    label="客户姓名"
                    width="160"
                    align="left">
                    <template slot-scope="scope">
                        <el-input type="text" size="mini" v-model="scope.row.full_name">
                    </template>
                </el-table-column>

                <el-table-column
                    prop="mobile"
                    label="客户手机"
                    width="160"
                    align="center">
                    <template slot-scope="scope">
                        <el-input type="text" size="mini" v-model="scope.row.mobile">
                    </template>
                </el-table-column>

                <el-table-column
                    prop="cus_from"
                    label="客户来源"
                    width="160"
                    align="center">
                    <template slot-scope="scope">
                        <el-input type="text" size="mini" v-model="scope.row.cus_from">
                    </template>
                </el-table-column>

                <el-table-column
                    prop="birthday"
                    label="客户生日"
                    width="160"
                    align="left">
                    <template slot-scope="scope">
                        <el-date-picker
                            v-model="scope.row.birthday"
                            type="date"
                            placeholder="客户生日">
                        </el-date-picker>
                    </template>
                </el-table-column>

                <el-table-column
                    prop="idnumber"
                    label="身份证号码"
                    width="160"
                    align="center">
                    <template slot-scope="scope">
                        <el-input type="text" size="mini" v-model="scope.row.idnumber">
                    </template>
                </el-table-column>

                <el-table-column
                    prop="area"
                    label="所在区域"
                    width="160"
                    align="center">
                    <template slot-scope="scope">
                        <el-input type="text" size="mini" v-model="scope.row.area">
                    </template>
                </el-table-column>

                <el-table-column
                    prop="address"
                    label="详细地址"
                    width="160"
                    align="center">
                    <template slot-scope="scope">
                        <el-input type="text" size="mini" v-model="scope.row.address">
                    </template>
                </el-table-column>

                <el-table-column
                    prop="wheregone"
                    label="去过景点"
                    width="160"
                    align="center">
                    <template slot-scope="scope">
                        <el-input type="text" size="mini" v-model="scope.row.wheregone">
                    </template>
                </el-table-column>

                <el-table-column
                    prop="remark"
                    label="备注信息"
                    width="160"
                    align="center">
                    <template slot-scope="scope">
                        <el-input type="text" size="mini" v-model="scope.row.remark">
                    </template>
                </el-table-column>

                <el-table-column
                    prop="remark"
                    label="操作"
                    width="60"
                    fixed="right"
                    align="center">
                    <template slot-scope="scope">
                        <el-link :underline="false" size="mini" type="danger" @click.native.prevent="deleteWaitingUser(scope.$index, waitingUploadUser)">移除</el-link>
                    </template>
                </el-table-column>
            </el-table>
        </div>

        <div slot="footer">
            <el-button size="small" type="primary" @click="doSaveLoadWaitingUsers()">确定导入</el-button>
            <el-button size="small" @click="waitingUploadUserFlag = false">取消</el-button>
        </div>
    </el-dialog>
</div>
{/block}
{block name="script"}
<script>
    var roles         = "{$_admin['roles']}";
    var adminId       = parseInt("{$_admin['id']}");
    var is_senior_admin = roles.split(',').includes('26') || (adminId ==1);
    var _formData = {
        uid: '',
        full_name: '',
        mobile: '',
        birthday: '',
        tour_perfer: '',
        tour_target: '',
        gender: '',
        status:'',
        wheregone: '',
        cus_from: '',
        remark: '',
        idcard: {
            idnumber: ''
        },
        address: {
            province: '',
            city: '',
            area: '',
            address: ''
        }
    }
    var my = new Vue({
        el: "#myApp",
        data(){
            return {
                is_senior_admin: is_senior_admin,
                admin_id: adminId,
                dialogFormVisible: false,
                formData: _formData,
                rules: {
                    mobile: [
                        { required: true, message: '此项不能为空', trigger: 'blur' },
                    ]
                },
                rowsCount: 0,
                rows: [],
                where: {
                    keyword: '',
                    sales_admin_id: is_senior_admin ? '' : adminId,
                    processon_ignore_days: '',
                    status: '',
                    tour_perfer: '',
                    tour_target: '',
                    page: 1,
                    limit: pageSize,
                },
                loading:false,
                dialogBindVisible: false,
                bindForm: {
                    uid: 0,
                    sales_id: ''
                },
                processonStatus: [
                    {
                        day: 7,
                        text: '超过7天未联系'
                    },
                    {
                        day: 15,
                        text: '超过15天未联系'
                    },
                    {
                        day: 30,
                        text: '超过30天未联系'
                    }
                ],
                salesList: [],
                sendCouponFlag: false,
                coupons: [],
                couponForm: {
                    coupon_id: '',
                    uid: 0
                },
                couponRecordsLoading: false,
                couponRecords: {
                    coupon: {},
                    rows: [],
                    rowsCount: 0,
                },
                couponRecordsWhere: {
                    uid: '',
                    mobile: '',
                    page: 1,
                    limit: 5,
                },
                sendGoldsFlag: false,
                goldsForm: {
                    golds: 0,
                    uid: 0,
                    remark: '',
                },
                goldsRecordsLoading: false,
                goldsRecords: {
                    golds: {},
                    rows: [],
                    rowsCount: 0,
                },
                goldsRecordsWhere: {
                    uid: '',
                    page: 1,
                    limit: 5,
                },
                templateLoading: null,
                waitingUploadUser: [],
                waitingUploadUserFlag: false,
                checkFalse: false,
                multipleSelectionUids: []
            }
        },
        methods: {
            doLoadRows (page) {
                this.loading = true
                this.where.page  = page || 1
                axios.get(Url({a:'get_list' , q:this.where}))
                    .then(res => {
                        this.rows = res.data.data
                        this.rowsCount =res.data.count
                        this.loading = false
                    })
            },
            doSetStatus (row) {
                axios.get(Url({a:'set_status',q:{status:row.status,id:row.uid,pk:'uid'}}))
                    .then(res => {
                        this.$message({
                            message: res.data.msg,
                            type: res.data.code === 200 ? 'success' : 'error',
                            onClose: _ => {
                                if (res.data.code !== 200) {
                                    this.doLoadRows()
                                }
                            }
                        })
                    })
            },
            doModify (row) {
                this.formData.uid = row.uid || 0
                if ( !this.formData.uid ) {
                    return this.$message.error('操作失败请稍后再试')
                }

                this.formData.full_name = row.full_name || ''
                this.formData.mobile = row.mobile || ''
                this.formData.birthday = row.birthday || ''
                this.formData.tour_perfer = row.tour_perfer || ''
                this.formData.tour_target = row.tour_target || ''
                this.formData.cus_from = row.cus_from || ''
                this.formData.gender = row.gender || 0
                this.formData.status = row.status || 0
                this.formData.wheregone = row.wheregone || ''
                this.formData.remark = row.remark || ''
                this.formData.idcard = row.idcard || {}
                this.formData.address = row.address.length > 0 ? row.address[0] : {}
                this.dialogFormVisible = true;
            },
            doBind(uid) {
                this.dialogBindVisible = true
                this.bindForm.uid = uid
            },
            loadSalesList() {
                axios.get(Url({c:'teachaffair.teacher',a:'get_list'})).then(res => {
                    this.salesList = res.data.data
                })
            },
            doSaveBind() {
                if ( !this.bindForm.uid ) return this.$message.error('UID不能为空')
                if ( !this.bindForm.sales_id ) return this.$message.error('销售经理ID不能为空')
                axios.post( Url({a:'saveBind'}) , this.bindForm).then(res => {
                    this.$message({
                        message: res.data.msg,
                        type: res.data.code === 200 ? 'success' : 'error',
                        duration:1500
                    });
                    this.dialogBindVisible = false;
                    this.doLoadRows(1)
                }).catch(_ => {
                    this.$message.error('操作失败')
                })
            },
            closeDialog () {
                this.$refs['formData'].clearValidate();
            },
            doSave (formName ) {
                if ( this.formData.idcard.idnumber && !this.formData.full_name ) {
                    return this.$message.error('填写身份证号码时必须同时填写真实姓名')
                }

                this.$refs[formName].validate((valid) => {
                    if (valid) {
                        const loading = this.$loading({
                            lock: true,
                            text: '处理中...',
                            spinner: 'el-icon-loading',
                            background: 'rgba(0, 0, 0, 0.7)'
                        });

                        axios.post( Url({a:'save'}) , this.formData).then(res => {
                            this.$message({
                                message:'操作成功',
                                type:'success',
                                duration:1500
                            });

                            loading.close()
                            this.dialogFormVisible = false;
                            this.doLoadRows(1)
                        }).catch(_ => {
                            this.$message({
                                message: '操作失败',
                                type: 'error'
                            })
                        })
                    } else {
                        console.log('error submit!!');
                        return false;
                    }
                });
            }
            ,loadCoupons() {
                axios.get(Url({c:'finance.coupon',a:'get_all',q:{status:1}})).then(res => {
                    this.coupons = res.data.data
                })
            }
            // 发放优惠券界面弹出
            ,doIssueCoupon(uid) {
                this.couponForm.uid = uid
                this.sendCouponFlag = true

                this.doLoadCouponRecordsRows()
            }
            // 确定发送优惠券
            ,doSaveIssue() {
                if ( !this.couponForm.uid ) return this.$message.error('UID不能为空')
                if ( !this.couponForm.coupon_id ) return this.$message.error('代金券ID不能为空')
                axios.post( Url({a:'saveIssueCoupon'}) , this.couponForm).then(res => {
                    this.$message({
                        message: res.data.msg,
                        type: res.data.code === 200 ? 'success' : 'error',
                        duration:1500
                    });
                    this.sendCouponFlag = false;
                }).catch(_ => {
                    this.$message.error('操作失败')
                })
            }
            // 加载用户已有领券记录
            ,doLoadCouponRecordsRows(page) {
                this.couponRecordsWhere.page = page || 1
                this.couponRecordsWhere.uid  = this.couponForm.uid
                axios.get(Url({c:'finance.coupon_records',a:'get_list',q:this.couponRecordsWhere}))
                .then(res => {
                    this.couponRecords.rows = res.data.data
                    this.couponRecords.rowsCount = res.data.count
                    this.couponRecordsLoading = false
                })
            }
            ,verifyCoupon(recId) {
                this.$confirm('此操作不可撤销，确认核销该券吗?').then(_ => {
                    axios.post(Url({c:'finance.coupon_records', a:'verifyCoupon'}) , {recId:recId}).then(res => {
                        this.$message({
                            message: res.data.msg,
                            type: res.data.code === 200 ? 'success' : 'error',
                        })
                    }).catch(_ => {
                        this.$message({
                            message: '核销失败',
                            type: 'error'
                        })
                    })

                    return this.doLoadCouponRecordsRows();
                }).catch(_ => {})
            }
            // 发放金币界面弹出
            ,doIssueGolds(uid) {
                this.goldsForm.uid = uid
                this.goldsForm.golds = 0
                this.goldsForm.remark = ''
                this.sendGoldsFlag = true

                this.doLoadGoldsRecordsRows()
            }
            // 确定发送金币
            ,doSaveIssueGolds() {
                if ( !this.goldsForm.uid ) return this.$message.error('UID不能为空')
                if ( this.goldsForm.golds < 1 ) return this.$message.error('金币数量至少为1')
                axios.post( Url({c: 'finance.gold', a:'saveIssueGolds'}) , this.goldsForm).then(res => {
                    this.$message({
                        message: res.data.msg,
                        type: res.data.code === 200 ? 'success' : 'error',
                        duration:1500
                    });
                    this.sendGoldsFlag = false;
                    this.doLoadRows()
                }).catch(_ => {
                    this.$message.error('操作失败')
                })
            }
            // 加载用户已有金币记录
            ,doLoadGoldsRecordsRows(page) {
                this.goldsRecordsWhere.page = page || 1
                this.goldsRecordsWhere.uid  = this.goldsForm.uid
                axios.get(Url({c:'user.user_golds_bill',a:'get_list',q:this.goldsRecordsWhere}))
                .then(res => {
                    this.goldsRecords.rows = res.data.data
                    this.goldsRecords.rowsCount = res.data.count
                    this.goldsRecordsLoading = false
                })
            }
            // 下载模板
            ,downloadTemplete() {
                window.location.href = Url({c:'user.user',a:'downloadTemplete'})
            }
            // 导入信息
            ,uploadTemplete() {
                window.location.href = Url({c:'user.user',a:'uploadTemplete'})
            }
            ,handleTemplateSuccess(res, file , fileList) {
                this.waitingUploadUserFlag = true
                this.waitingUploadUser = res.data || []
                this.templateLoading.close()

                this.calcWaitingUsersRepeat()
            }
            ,calcWaitingUsersRepeat()
            {
                for ( let i=0; i<= this.waitingUploadUser.length; i++ ) {
                    let _user = this.waitingUploadUser[i]
                    if ( _user.repeat_flag > 0 ) {
                        this.checkFalse = true
                        break
                    }
                }
            }
            ,onChangeTemplate( file, fileList ) {
                this.templateLoading = this.$loading({
                    lock: true,
                    text: '处理中...',
                    spinner: 'el-icon-loading',
                    background: 'rgba(0, 0, 0, 0.7)'
                });
            }
            ,deleteWaitingUser(index, rows) {
                rows.splice(index, 1);
            }
            ,doSaveLoadWaitingUsers() {
                const loading = this.$loading({
                    lock: true,
                    text: '处理中...',
                    spinner: 'el-icon-loading',
                    background: 'rgba(0, 0, 0, 0.7)'
                });

                axios.post( Url({c: 'user.user', a:'saveTemplate'}) , this.waitingUploadUser).then(res => {
                    this.$message({
                        message: res.data.msg,
                        type: res.data.code === 200 ? 'success' : 'error',
                        duration:1500
                    });

                    loading.close()

                    if ( res.data.code == 200 ) {
                        this.waitingUploadUser = []
                        this.waitingUploadUserFlag = false
                        this.doLoadRows()
                    }
                }).catch(_ => {
                    this.$message.error('操作失败')
                })
            }
            ,doDelete(uid) {
                this.$confirm('将删除用户及其所有数据。此操作不可撤销，确认删除吗?').then(_ => {
                    axios.post(Url({c:'user.user', a:'deleteUser'}) , {uid:uid}).then(res => {
                        this.$message({
                            message: res.data.msg,
                            type: res.data.code === 200 ? 'success' : 'error',
                        })
                    }).catch(_ => {
                        this.$message({
                            message: '删除失败',
                            type: 'error'
                        })
                    })

                    return this.doLoadRows(1)
                }).catch(_ => {})
            }
            ,handleSelectionChange(vals) {
                this.multipleSelectionUids = []
                for ( let i = 0; i < vals.length; i++ ) {
                    let _user = vals[i]
                    if ( _user.uid != undefined ) {
                        this.multipleSelectionUids.push(_user.uid)
                    }
                }
            }
            ,confirmGetBack(unfollowId , status) {
                let msg = '确认该操作码？';
                if ( status == 1 ) msg = '确认收回该用户并归属到总账号吗?';
                if ( status == 2 ) msg = '确认取消收回该用户吗?';
                this.$confirm(msg).then(_ => {
                    axios.post(Url({c:'user.user', a:'confirmGetBack'}) , {id: unfollowId , status: status}).then(res => {
                        this.$message.success('操作成功')
                    }).catch(_ => {
                        this.$message.error('操作失败')
                    })
                    return this.doLoadRows(1)
                })
            }
        },
        mounted(){
            this.doLoadRows()
            this.loadSalesList()
            this.loadCoupons()
        }
    })
</script>
{/block}